/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.institution.controller;


import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.permission.SPIAccountAnno;

import com.koron.institution.service.api.LawCorpService;
import com.koron.institution.uitls.BusinessCode;
import com.koron.system.annotation.Log;
import com.koron.system.discrete.BusinessManipulation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import org.swan.bean.MessageBean;
import springfox.documentation.annotations.ApiIgnore;


@Api(tags = "LawCorp", description = "法规标准Api类")
@RestController
@RequestMapping(value = "/lawCorp")
public class LawCorpController {

    @Autowired
    private LawCorpService lawCorpService;

    private static final Logger logger = LoggerFactory.getLogger(LawCorpController.class);

    @ApiOperation("法规标准列表")
    @RequestMapping(value = "/list.htm", method = {RequestMethod.GET})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fileName", value = "文件名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "corpCode", value = "公司code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "state", value = "状态(0.正常，1.新增审核中,2修改审核中,3废除审核中)", required = true, paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "categoryId", value = "目录id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "当前页", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query", dataType = "Integer")})
    public MessageBean<?> list(String fileName, String corpCode, Integer state, String categoryId, Integer page,
                               Integer pageSize, @SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user) {

        return lawCorpService.getList(fileName, corpCode, state, categoryId, page, pageSize);
    }

    @ApiOperation("法规标准可引入下拉列表")
    @RequestMapping(value = "/selectList.htm", method = {RequestMethod.GET})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "公司code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "categoryId", value = "目录id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "fileName", value = "文件名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "当前页", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query", dataType = "Integer")
    })
    public MessageBean<?> selectList(String corpCode, @SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                                     String categoryId, String fileName, Integer page,
                                     Integer pageSize) {

        return lawCorpService.selectList(corpCode, categoryId, fileName, page, pageSize);
    }

    @ApiOperation("法规引入")
    @RequestMapping(value = "/saveOrCommit.htm", method = {RequestMethod.POST})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "法规对象字符串", name = "lawCorpStr", required = true),
            @ApiImplicitParam(value = "操作类型:0草稿,1提交", name = "operationType", required = true),
            @ApiImplicitParam(name = "approverCodeListStr", value = "审批人code集合字符串", required = true, paramType = "query", dataType = "String"),
    })
    @Log(title = "法规引入",businessModule = "法规管理", businessManipulation = BusinessManipulation.INSERT)
    public MessageBean<?> saveOrCommit(String lawCorpListStr, @SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                                       String approverCodeListStr, Integer operationType) {
        if (null==user){
            MessageBean<?> msg=new MessageBean<>();
            msg.setCode(BusinessCode.NOT_LONGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LONGIN.getDescription());
            return msg;
        }
        return lawCorpService.saveOrCommit(lawCorpListStr, user, approverCodeListStr, operationType);
    }

    @ApiOperation("废弃制度")
    @RequestMapping(value = "/discard.htm", method = {RequestMethod.POST})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lawCorpId", value = "制度id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "approverCodeListStr", value = "审批人code集合字符串", required = true, paramType = "query", dataType = "String"),
    })
    @Log(title = "废弃制度删除",businessModule = "法规管理", businessManipulation = BusinessManipulation.DELETE)
    public MessageBean<?> discard(String lawCorpId, @SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String approverCodeListStr) {
        if (null==user){
            MessageBean<?> msg=new MessageBean<>();
            msg.setCode(BusinessCode.NOT_LONGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LONGIN.getDescription());
            return msg;
        }
        return lawCorpService.discard(lawCorpId, user, approverCodeListStr);
    }

    @ApiOperation("流程中的业务数据")
    @ApiImplicitParam(name = "ids", value = "流程关联的业务ids", required = true, paramType = "query", dataType = "String")
    @RequestMapping(value = "/getProcessData.htm", method = {RequestMethod.GET})
    public MessageBean<?> getProcessData(String ids) {
        return lawCorpService.getProcessData(ids);
    }
}
